<template lang="jade">

    div.return-bar
        i.iconfont(@click="back()") &#xe668;
        交易流水


    div.user-center.detail_top(v-infinite-scroll="down()", infinite-scroll-disabled="busy", infinite-scroll-distance="10")

        div(v-for=" (index, item) in items ")
            dl.money_record(v-for=" (index, a) in item ")
                dt {{index}}
                dd( v-for=" (index, b) in a ")
                    span.date {{b.addtime}}
                    span.content
                        b( v-bind:class="{ 'in': b.symbol=='+', 'green': b.symbol=='-' }" ) {{b.type}}: {{b.symbol}} {{b.money}}
                        strong 余额:{{b.balance}}
                        em {{b.remark}}

</template>


<script>
import '../../assets/sass/user/index.scss'
import {c_flow_list, c_money_record, Api_Transaction_Records} from '../../config/api'

Date.prototype.format = function(fmt) {
     var o = {
        "M+" : this.getMonth()+1,                 //月份
        "d+" : this.getDate(),                    //日
        "h+" : this.getHours(),                   //小时
        "m+" : this.getMinutes(),                 //分
        "s+" : this.getSeconds(),                 //秒
        "q+" : Math.floor((this.getMonth()+3)/3), //季度
        "S"  : this.getMilliseconds()             //毫秒
    };
    if(/(y+)/.test(fmt)) {
            fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
    }
     for(var k in o) {
        if(new RegExp("("+ k +")").test(fmt)){
             fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
         }
     }
    return fmt;
}


export default {

  data () {
    return {
    	record_type:'',
		filter_type:'',
		showFilter:false,
		filter_duration:'',
		filter_duration_txt:'时间段',
		busy:true,
        page:1,
		items:[],
		filter_status:'',
		filter_status_txt:'记录状态'
    }
  },

  methods: {
    down: function() {

      if(this.busy == true || this.items == ''){
        return false;
      }
      this.busy = true;
      this.fetch(++this.page);
    },
    setFilter(key){
    	this.filter_type = key;
    },

    setFilterStatus(key, txt){
    	this.filter_status = key;
    	this.filter_type = this.filter_type+'1';
    	this.filter_status_txt = txt;
    	this.fetch(1);
    },


    setFilterDuration(key, txt){
    	this.filter_duration = key;
    	this.fetch(1);
    	this.filter_type = this.filter_type+'1';
    	this.filter_duration_txt = txt
    },
    getItemName(type, status){
    	var r_val = "";
    	switch(type){
    		case "1":
    			r_val = "充值";
    			break;
    		case "2":
    			r_val = "提现";
    			break;
    		default:
    			r_val = "冻结";
    			break;
    	}

    	switch(status){
    		case "0":
    			r_val += "处理中";
    			break;
    		case "1":
    			r_val += "成功";
    			break;
    		case "2":
    			r_val += "失败";
    			break;
    	}
    	return r_val;
    },

    getItemClass(type, status){
    	var r_val = "";
    	switch(status){
    		case "1":
    			r_val = "";
    			break;
    		case "2":
    			r_val = "grey";
    			break;
    		default:
    			r_val = "blue";
    			break;
    	}
    	if(type=="2" && status=="1")
    		r_val = "green";


    	return r_val;
    },

    showFilterFun(){
    	this.showFilter = !this.showFilter;
    },
    setView(key){
      this.subview = key;
    },

    back(){
      window.history.back();
    },

    setRecordType(key){
    	this.record_type = key;
    	this.fetch(1);
    },



    getDat(key){

        var oldTime = (new Date(key)).getTime();
        var curTime = new Date(oldTime).format("MM-dd hh:mm");
        return curTime;
    },

	fetch: function (page) {
        var that = this;
        this.$store.dispatch('setShowLoading', true);
		//var data = {'page': page}
		this.$http({url: c_flow_list+'&number=10&type='+this.record_type+'&status='+this.filter_status+'&time_status='+this.filter_duration+'&page='+this.page, method: 'GET'}).then(function (response) {

            /*var obj = response.data;
            if(!obj.status){
                alert(obj.msg)
                if(obj.code == '10055'){
                    sessionStorage.removeItem("login");
                    this.$route.router.go('/login?from='+this.$route.path.substring(1))
                }
                return;
            }*/

            /*console.log(this.items)
            if(this.items.length == 0 )
                this.items = response.data.data.list;
            else
                this.items = this.items.push(response.data.data.list);*/
                this.$store.dispatch('setShowLoading', false);
                var obj = response.data;
                if(obj.status){
                    this.items = this.items.concat(response.data.data.list);
                    this.busy = false;
                }else{
                    this.busy = true;
                }


		});
	}
  },
  route: {
    activate ( transition ) {
        transition.next();
		this.fetch(1)
    }
  }
}
</script>
